package com.huabo.fxgl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hbfk.util.JsonBean;
import com.huabo.fxgl.entity.Find;
import com.huabo.fxgl.entity.Organization;
import com.huabo.fxgl.entity.Staff;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/demo")
//@Api(tags = "风险管控模块的测试Controller")
public class DemoController {

    @RequestMapping("/index")
    @ResponseBody
    @ApiOperation("/demo/index")
    public JsonBean index(@ApiParam(name = "author", value = "开发者名字") String author,
                          @ApiParam(name = "version", value = "版本号")String version) {
        JsonBean jsonBean = new JsonBean();
        JsonBean.success("success");
//        jsonBean.setCode(200);
        jsonBean.setData("Author: " + author + ", Version: " + version);
        return jsonBean;
    }

    /**
     * 风险管控 - 风险监控 - 供应商监控 - 供应商列表
     * @author LiYe
     * @version 1.0.1
     * @date 2022/8/2
     * @param find
     * @return
     */
    @RequestMapping(value = "/fxyj/fxyj_list")
//    @ApiOperation("/fxxt/fxyj/fxyj_list")
    public ModelAndView fxyj_fxyj_list(@ApiParam(name = "find", value = "find") Find find,
                                        @ApiParam(name = "pageNumber", value = "pageNumber") @RequestParam(defaultValue = "1") Integer pageNumber,
                                       @ApiParam(name = "limit", value = "limit") @RequestParam(defaultValue = "15") Integer limit,
                                       @ApiParam(name = "teamid", value = "teamid") Integer teamid,
                                       @ApiParam(name = "staff", value = "staff") Staff staff,
                                       @ApiParam(name = "organization", value = "organization") Organization organization) {
        /*String number = request.getParameter("pageNumber");
        String teamid = request.getParameter("teamid");
        ModelAndView mv = new ModelAndView();
        Integer pageNumber = 1;
        if (number != null && number.length() > 0) {
            pageNumber = Integer.parseInt(number);
        }*/
//        TblStaff tblStaff = (TblStaff) request.getSession().getAttribute("longUser");
//        TblOrganization attribute1 = (TblOrganization) request.getSession().getAttribute("hbOrgEntity");// 当前用户的机构

       /* IPage pageBean = new Page(pageNumber, limit);//分页设置
        if(teamid!=null && teamid.trim().length()>0) {
            pageBean = tblyyCompanyService.findByCompay(find, pageNumber, pageBean.getPageSize(),  new BigDecimal(teamid));
            @SuppressWarnings("unchecked")
            List<TblyyCompany> list = pageBean.getRecordList();
            List<TblyyCompany> newlist =new ArrayList<TblyyCompany>();
            if(list!=null && list.size()>0) {
                for (TblyyCompany tblyyCompany : list) {
                    List<Tblyyprice> list2 = tblyypriceService.findByIs(tblyyCompany.getReportmodel().getPriceid());
                    tblyyCompany.setList(list2);
                    newlist.add(tblyyCompany);
                }
                pageBean.setRecordList(newlist);
            }
        }else {
            pageBean =tblyyCompanyService.findBySqlPage(find,tblStaff.getStaffid(), pageNumber, pageBean.getPageSize(), attribute1.getOrgid());
            List<TblyyCompany> list = pageBean.getRecordList();
            List<TblyyCompany> newlist =new ArrayList<TblyyCompany>();
            if(list!=null && list.size()>0) {
                for (TblyyCompany tblyyCompany : list) {
                    List<Tblyyprice> list2 = tblyypriceService.findByIs(tblyyCompany.getReportmodel().getPriceid());
                    tblyyCompany.setList(list2);
                    newlist.add(tblyyCompany);
                }
                pageBean.setRecordList(newlist);
            }
        }
        mv.setViewName("/fxgl/fxyj/fxyj_list");
        mv.addObject("pageBean", pageBean);
        mv.addObject("teamid", teamid);
        mv.addObject("pageNumber", pageNumber);
        return mv;*/
        return null;
    }
/*
    @PostMapping(path = "/index", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiOperation("demo-index")
    public JsonBean index(@ApiParam(name = "params", value = "params") @RequestBody Map params) {
        JsonBean jsonBean = new JsonBean();
        JsonBean.success("success");
//        jsonBean.setCode(200);
        jsonBean.setData("Author: " + params.get("author") + ", Version: " + params.get("version"));
        return jsonBean;
    }*/
}
